package com.ruanko.banking;

/**
 * 信用卡
 * 
 */
public class CreditCard extends Card {

	/**
	 * 信誉度
	 */
	private double credit;
	
	/**
	 * 无参构造方法
	 */
	public CreditCard() {
		this.credit = 10000.0;
	}

	/**
	 * 带参构造方法，初始化余额
	 * @param money
	 */
	public CreditCard(double money) {
		super(money);
		this.credit = 10000.0;
	}
	
	/**
	 * 信用卡存款
	 */
	@Override
	public void save(final double money) {
		// 透支 && 足以还清欠款，还款后余额超出1000
		if (this.balance < 0 && money >= 1000 - this.balance) {
			// 信用额度增加100.0
			this.credit += 100.0;
			
			System.out.printf("信用额度增加100，当前额度：%.2f\n", this.credit);
		}
		
		// 增加余额(存款)
		this.balance += money;
	}

	/**
	 * 信用卡取款
	 */
	@Override
	public void take(final double money) {
		
		if (this.balance >= money) {
			// 没有透支，直接取款
			this.balance -= money;
			
		} else {// 透支
			// 计算透支金额
			double overdraft = money;
			if (this.balance > 0) {
				overdraft -= this.balance;
			}
			
			// 根据透支金额，计算手续费
			double fee = 0.0;
			if (overdraft <= 2000) {
				fee = 10.0;
			} else if (overdraft <= 5000) {
				fee = 30.0;
			} else {
				fee = overdraft * 0.01;
			}
			
			// 判断钱还够不够
			if (money + fee > this.balance + this.credit) {
				System.out.println("您已过度透支，取款失败！");
			} else {
				this.balance -= money;
				this.balance -= fee;
				
				System.out.printf("透支：%.2f，扣除手续费：%.2f。\n", overdraft, fee);
			}
			
			System.out.printf("剩余额度：%.2f\n", (this.credit + this.balance));
		}
		
	}
	
}
